﻿/*
js工具开发包
author:L-HuiXin
*/


/*
Script: Elements.js
    Contains get Elements 

License:
    MIT-style license.
*/
var MyUtil = {};
MyUtil.$ = function(elementId){
	return document.getElementById(elementId);
}

MyUtil.getElementByCss = function(obj,name,value){
	for( i=0;i<obj.length;i++){
		var temp = obj[i];
		//alert(obj[i].getAttribute('style'));
		eval("var a=obj[i]."+name);
		if(a== value){      
			return obj[i];
			break;
		}
	}
}

/*
Script: Listener.js
    Contains Compatible IE/FireFox addListener 

License:
    MIT-style license.
*/

MyUtil.addEvent = function(obj,event,fun){
 if(window.addEventListener) {
     obj.addEventListener(event,fun,false); //火狐添加监听
    }else{
     obj.attachEvent("on"+event,fun);//IE添加单击监听
    };
}


/*
Script: Cookie.js
    Contains get&set Cookie 

License:
    MIT-style license.
*/

function getCookie(name){
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if((!start)&&(name!=document.cookie.substring(0,name.length))){
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {expires = expires * 1000 * 60 * 60 * 24;}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) + (( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + (( path ) ? ';path=' + path : '' ) + (( domain ) ? ';domain=' + domain : '' ) + (( secure ) ? ';secure' : '' );
}

function setCookie_local( name, value, expires, path,  secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;    
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) + (( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + (( path ) ? ';path=' + path : '' ) + (( secure ) ? ';secure' : '' );
}
	
function deleteCookie(name,path,domain){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	if ( getCookie( name ) )
		document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') + ((domain)? ';domain=' + domain : '' ) + ';expires='+exp.toGMTString();
}
